package org.acompanhamento.domain;

import static javax.persistence.FetchType.LAZY;

import java.util.Collections;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import jmine.tec.aom.domain.Property;
import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Index;

import org.hibernate.annotations.Type;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.persister.annotation.NaturalKey;
import bancosys.tec.utils.date.Date;

/**
 * 
 * @author icaro.kume
 *
 */
@Entity
@Table(name = "TASK")
@Alias("TASK")
@Documentation("AGILE TEAM TASK")
@SequenceGenerator(name = "SEQ_TASK", sequenceName = "SEQ_TASK")
public class Task extends PropertizedEntity {

	private Long id;

	private String identifier;

	private String description;

	private String summary;

	private Long points;

	private Sprint sprint;

	private Status status;

	private Member responsible;

	private Date recordDate;

	@Id
	@GeneratedValue(generator = "SEQ_TASK")
	@Column(name = "COD_TASK", nullable = false)
	@Documentation("TASK ID")
	public Long getId() {
		return this.id;
	}

	@NaturalKey
	@Index(suffix = "0")
	@Column(name = "IDENTIFIER", nullable = false)
	@Documentation("TASK IDENTIFIER")
	public String getIdentifier() {
		return this.identifier;
	}

	@Column(name = "DESCRIPTION", nullable = false)
	@Documentation("TASK DESCRIPTION")
	public String getDescription() {
		return this.description;
	}

	@Column(name = "SUMMARY", nullable = false)
	@Documentation("TASK SUMMARY")
	public String getSummary() {
		return this.summary;
	}

	@Column(name = "POINTS", nullable = false)
	@Documentation("TASK POINTS")
	public Long getPoints() {
		return this.points;
	}

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "SPRINT")
	@Documentation("TASK SPRINT")
	public Sprint getSprint() {
		return this.sprint;
	}

	// TODO: talvez deva existir um controle maior do status, sabendo quando foi
	// alterado, e outras coisas, assim como respons��vel
	@Index(suffix = "2")
	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "COD_STATUS", nullable = false)
	@Documentation("TASK STATUS")
	public Status getStatus() {
		return this.status;
	}

	// TODO: idem ao status
	@Index(suffix = "3")
	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "COD_MEMBER")
	@Documentation("TASK RESPONSIBLE")
	public Member getResponsible() {
		return this.responsible;
	}

	@Type(type = "bancosys.tec.persist.hibernate.type.DateType")
	@Column(name = "DT_RECORD", nullable = false)
	@Documentation("TASK RECORD DATE")
	public Date getRecordDate() {
		return this.recordDate;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public void setPoints(Long points) {
		this.points = points;
	}

	public void setSprint(Sprint sprint) {
		this.sprint = sprint;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public void setResponsible(Member responsible) {
		this.responsible = responsible;
	}

	public void setRecordDate(Date recordDate) {
		this.recordDate = recordDate;
	}

	@Override
	@Transient
	protected Set<Property> getEntityProperties() {
		return Collections.emptySet();
	}

}
